<?

use Workerman\Worker;
use Workerman\Connection\TcpConnection;
require_once __DIR__ . '/vendor/autoload.php';

// 注意：这里与上个例子不同，使用的是websocket协议
$ws_worker = new Worker("websocket://0.0.0.0:2000");

// 启动4个进程对外提供服务
$ws_worker->count = 4;
  
// 当收到客户端发来的数据后返回hello $data给客户端
$ws_worker->onMessage = function(TcpConnection $connection, $message) use ($ws_worker)
{
    // 向客户端发送hello $data
   
    // print_r(json_decode($message,true));
    echo count($ws_worker->connections).PHP_EOL;
    $msg = "test";
    foreach($ws_worker->connections as $con){
       
        $connection->send("SDFSdfsd");
        echo "游客：".$con->id.", page:".$msg.PHP_EOL;
    }

};

// 运行worker
Worker::runAll();
